package org.wolfengi.monitor.service.impl;

import org.wolfengi.monitor.common.ShipCN;
import org.wolfengi.monitor.entity.FShipGroupCount;
import org.wolfengi.monitor.mapper.FShipGroupCountMapper;
import org.wolfengi.monitor.service.FShipGroupCountService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wolfengi
 * @since 2020-05-20
 */
@Service
public class FShipGroupCountServiceImpl extends ServiceImpl<FShipGroupCountMapper, FShipGroupCount> implements FShipGroupCountService {

    @Autowired
    private FShipGroupCountMapper fShipGroupCountMapper;

    @Override
    public List<Map> getList() {
        List<FShipGroupCount> list = fShipGroupCountMapper.selectList(null);

        List<Map> res = new ArrayList<>();
        list.forEach(l -> {
            Map<String, Object> map = new HashMap<>();
            String cn = ShipCN.getCNTrim(l.getStateType());

            String[] states = l.getStateType().split("@");
            String state = ShipCN.getCNTrim(states[0]);
            String fault = ShipCN.getCNTrim(states[1]);
            map.put("name", state + " " + fault);
            map.put("value", l.getCount());
            res.add(map);
        });
        return res;
    }
}
